Compound Patterns

A lot of patterns work together very well to form compound patterns. Shown is a UML class diagram that implements various design patterns to form a compound pattern. Here are some notes describing how and why this design was arrived at.
- Polymorphism was introduced by the use of the
Quackableinterface. This makes a number of design patterns available to us. - The decorator pattern is used to allow us to track the number of times the method quack() is called. Using the
decorator pattern means we don't have to modify
DuckandDuckCallQuackDecoratorimplementsQuackableso it can be referenced as aQuackabletypeQuackDecoratorhas aQuackableinstance variable so it can be passed aQuackabletypeQuackDecoratoris the first object in the chain, so it'squack()method is called first. This allows it to update a counter variable, then call thequack()of itsQuackableinstance variable
- To use the
Gooseclass, the adapter pattern is utilised so that we can convert the call toGoose'shonk()method toQuackablesquack()method. Note thatGooseAdapterimplementsQuackableso we can refer to all our objects as the sameQuackabletype. - A factory pattern method is used to create our objects, so that we separate object creation from object use.